package pers.qianyu.controller;


import lombok.extern.slf4j.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import pers.qianyu.domain.*;
import pers.qianyu.service.*;

@RestController
@Slf4j
public class ProductController {
    @Autowired
    private ProductService productService;

    //减少库存
    @RequestMapping("/product/reduceInventory")
    public void reduceInventory(Integer pid, Integer num) {
        productService.reduceInventory(pid, num);
    }

    @GetMapping("/product/{pid}")
    public Product product(@PathVariable Integer pid) {
        log.info("查询id为{}的商品", pid);
        Product product = productService.findById(pid);
        log.info("商品信息查询成功：{}", product.toString());
        return product;
    }
}